<template>
	<view>
		<view class="swiper-img">
			<u-swiper height="350" class="swiper-list" :list="info" mode="round" :effect3d="false" duration="500" interval="3000"
			 @click="selectWhat">
			</u-swiper>
		</view>
	</view>
</template>

<script>
	import config from '../../../utils/config.js'
	export default {
		data() {
			return {
				info: []
			}
		},
		computed: {
			swipperData() {
				// console.log(this.dataList)
				var list = []
				var pic = []
				if (this.dataList !== null) {
					var houseInfo = this.dataList.houseInfo
					//获取图片的路径
					for (let i = 0; i < houseInfo.list.length; i++) {
						let picPath = ''
						// let imageAddressList = houseInfo.list[i].imageAddressList
						// picPath = config.host + imageAddressList[0].address
						let house = []
						house = houseInfo.list[i].house
						if (house.indexImage !== '' && house.indexImage !== null) {
							picPath = config.host + house.indexImage
						}
						let title = house.address
						var sign = ''
						if (house.type === 0) {
							sign = '出租'
						} else {
							sign = '出售'
						}
						pic.push(picPath)
						let data = {
							"houseId": house.id,
							"picPath": picPath,
							"title": title,
							"type": house.type,
							"price": house.price,
							"sign": sign
						}
						list.push(data)
					}
					this.info = pic
					var show = {
						"list": list
					}
					return show
				}
				return null
			}

		},
		methods: {
			selectWhat(e) {
				var image = ''
				this.info.forEach((item, index) => {
					if(index === e){
						image = item
					}
				})
				for(let i = 0;i<this.swipperData.list.length;i++){
					if(this.swipperData.list[i].picPath === image){
						this.gotoDetail(this.swipperData.list[i].houseId,this.swipperData.list[i].type)
					}
				}
			},
			gotoDetail(houseId, type) {
				//跳转到租房或者卖房详情页
				if (type === 0) {
					wx.navigateTo({
						// url: 'test?id=1&name=uapp'  c传递参数
						url: '/pages/components/rentDetail?houseId=' + houseId + '&recommandId=' + this.dataList.recommandId
					})
				} else {
					wx.navigateTo({
						// url: 'test?id=1&name=uapp'  c传递参数
						url: '/pages/components/buyDetail?houseId=' + houseId + '&recommandId=' + this.dataList.recommandId
					})
				}
			}
		},
		props: {
			dataList: {}
		}
	}
</script>

<style>
	.swiper-img {
		margin-top: 20rpx;
	}

	.swiper-list {
		height: 320rpx;
		padding: 10rpx;
	}

	uni-swiper {
		height: 320rpx;
	}
</style>
